<?php
namespace Bus\Controller;
use Think\Controller;
class CustomController extends Controller {

	public function addCustom()
	{
		$custom['QR_Id']  = array('exp',' NOT IN (SELECT QR_Id FROM ad_custom_station)');
		$custom['bus_stop_flag']='A';
		$custom['bus_stop_state']=1;

		$data=M("qr")->where($custom)->order('QR_Id');

		//$data=M("qr");
		$list=$data->select();
		$this->assign('list',$list);

		$this->display();
	}

	public function addCustomHandle()
	{
		$custom=I('customname');
		foreach ($_POST['qrid'] as $k => $v) {
			$data[$k]['custom']=I('customname');
			$data[$k]['start_date']=I('startdate');
			$data[$k]['end_date']=I('enddate');
			$data[$k]['QR_Id']=$v;
		}
		//dump($data);
		M('custom_station')->addAll($data);
		$this->success('添加成功!',U('Bus/custom/custom/custom/'.$custom));

	}

	public function custom()
	{
		$list2="";
		if(isset($_GET['custom']))
		{
			$custom=$_GET['custom'];
			$data=M('custom_station')->where("custom='$custom'")->join('ad_qr ON ad_custom_station.QR_Id=ad_qr.QR_Id');
			$list2="custom";
		}
		else
		{
			//$custom['QR_Id']  = array('exp',' NOT IN (SELECT QR_Id FROM ad_custom_station)');
			//$data=M("qr")->where($custom);
			$data=M("qr")->where("bus_stop_flag='A' and bus_stop_state=1")->join('LEFT JOIN ad_custom_station ON ad_custom_station.QR_Id=ad_qr.QR_Id')->order('ad_qr.QR_Id');
		}
		$list=$data->select();
		//dump($list2);
		$this->assign('list',$list);
		$this->assign('list2',$list2);
		$this->display();
	}

	public function qr()
	{
		$data=M("qr")->where('bus_stop_state=1')->order('station_name');
		$list=$data->select();
		$this->assign('list',$list);
		$this->display();
	}

	public function testHandle()
	{
		if($_SESSION['shanghuname']==null || $_SESSION['shanghuname']== ''){
		$this->error("非法操作",U('Index/index'));
		}

		$id = $_SESSION['mid'];
		//$uid=M("mydianpu")->where(id=.$dp_id)->getField("id");
		$result = M("mydianpu")->where("id={$id}")->setField('id',$id);

		$cat_name=$_POST['dpname'];
		$cat_mon=$_POST['xmprice'];
		$cat_time=$_POST['xmtime'];
		$cat_xiala=$_POST['xmdanw'];



		$count = count($cat_name);

		$i = 0;
		$data = array();

		for($i=0; $i<$count;$i++){
		$data[$i]['dpname'] = $cat_name[$i];
		$data[$i]['xmprice'] = $cat_mon[$i];
		$data[$i]['xmtime'] = $cat_time[$i];
		$data[$i]['xmdanw'] = $cat_xiala[$i];

		}

		foreach($data as $k => $v ){

		$fat['dpname']=$v;
		$fat['xmprice']=$v;
		$fat['xmtime']=$v;
		$fat['xmdanw']=$v;	
		$fat['dtime']=time();
		$fat['mid']=$result;
		$fat['mdp_id']=$id;

		if($v!=""){
		M("mydianpuxm")->add($fat);
		}
		}


		$this->redirect("Product/product_add");
		$this->display();
		}

	

}